package com.bootlever.framework.rmi.proxy;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;

public class RmiProxyFactory<T> implements FactoryBean<T> {

    private Class<T> interfaceClass;
    private ApplicationContext applicationContext;

    @Override
    public T getObject() throws Exception {
        return (T) new RmiProxy().bind(interfaceClass, applicationContext);
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public Class<T> getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}
